<!--
 - MineAdmin is committed to providing solutions for quickly building web applications
 - Please view the LICENSE file that was distributed with this source code,
 - For the full copyright and license information.
 - Thank you very much for using MineAdmin.
 -
 - @Author X.Mo<root@imoi.cn>
 - @Link   https://gitee.com/xmo/mineadmin-vue
-->

<template>
  <a-modal v-model:visible="visible" fullscreen :footer="false">
    <template #title>维护 {{ currentRow.name }} 服务关系</template>
    <!-- CRUD 组件 -->
    <ma-crud :options="crud" :columns="columns" ref="crudRef">
    </ma-crud>
  </a-modal>
</template>

<script setup>
import { ref, reactive } from 'vue'
import areaService from '@/api/warehouse/areaService'
import dictHelp from "@/utils/dicthelp.js";

const crudRef = ref()
const visible = ref(false)
const currentRow = ref({ id: undefined, name: undefined })

const open = (row) => {
  currentRow.value = row
  crudRef.value.requestData()
  visible.value = true
}

const crud = reactive({
  autoRequest: false,
  api: areaService.getList,
  showIndex: false,
  pageLayout: 'fixed',
  rowSelection: { showCheckedAll: true },
  operationColumn: true,
  operationColumnWidth: 160,
  beforeAdd: (form) => {
    form.area_id = currentRow.value?.id
    return true
  },
  add: { show: true, api: areaService.save, auth: ['warehouse:areaService:save'] },
  edit: { show: true, api: areaService.update, auth: ['warehouse:areaService:update'] },
  delete: {
    show: true,
    api: areaService.deletes, auth: ['warehouse:areaService:delete'],
    realApi: areaService.realDeletes, realAuth: ['warehouse:areaService:realDeletes']
  },
  beforeRequest: (params) => params.area_id = currentRow.value.id
})

const columns = reactive([
  { title: 'ID', dataIndex: 'id', addDisplay: false, editDisplay: false, width: 50, hide: true },
  {
    title: '服务', dataIndex: 'service_id', search: true, width: 220,
    formType: "select",
    dict:dictHelp.service,
    commonRules: [{ required: true, message: '服务必选' }],
  },
  {
    title: '创建时间', dataIndex: 'created_at', addDisplay: false, editDisplay: false,
    search: true, formType: 'range', width: 180,
  }
])

defineExpose({ open })
</script>

<style scoped>
</style>